package net.zjitc.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.zjitc.common.ResponseResult;
import net.zjitc.entity.Company;
import net.zjitc.entity.Manager;
import net.zjitc.entity.User;
import net.zjitc.entity.Yonghu;
import net.zjitc.service.ICompanyService;
import net.zjitc.service.IManagerService;
import net.zjitc.service.IUserService;
import net.zjitc.service.IYonghuService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

/**
 * @auther 郭梦婷
 * @create 2022-05-23 17:09:09
 * @describe 前端控制器
 */
@CrossOrigin
@RestController
@Api(tags = "登录管理")
public class UserController {
    @Reference
    private IUserService userService;
    @Reference
    private IYonghuService yonghuService;
    @Reference
    private ICompanyService companyService;
    @Reference
    private IManagerService managerService;

    ResponseResult result=new ResponseResult();

    @ApiOperation("获取登录信息")
    @GetMapping("user")
    public ResponseResult getUserByUsername(@RequestParam String username){
        User user = userService.findByUsername(username);
        if(user!=null){
            result.setSuccess("用户存在",user);

        }else {
            result.setError("用户不存在");
        }
        return result;
    }
    @ApiOperation("获取登录的用户信息")
    @GetMapping("userByUsername")
    public ResponseResult getuserByUsername(@RequestParam String username){
        User user = userService.findByUsername(username);
        if (user.getRoleid()==2){
            Yonghu yonghu= yonghuService.getById(user.getActorid());
            result.setSuccess("获取用户成功",yonghu);

        }
        else if (user.getRoleid()==3){
            Company company= companyService.getById(user.getActorid());
            result.setSuccess("获取企业成功",company);
        }else {
            Manager manager = managerService.getById(user.getActorid());
            result.setSuccess("获取管理员成功",manager);
        }
        if (result.getData()==null){
            result.setError("获取失败");
        }
        return result;
    }


}

